<template>
	<view>
		<!-- 客户端 -->
		<Customer ref="customerRef" v-if="roleType === 'customer'"></Customer>

		<!-- 员工端 生产端 -->
		<Produce  ref="produceRef" v-if="roleType === 'staff' && staffRole === 'shengchan'"></Produce>

		<!-- 员工端 物流端 -->
		<Logistics ref="logisticsRef" v-if="roleType === 'staff' && staffRole === 'wuliu'"></Logistics>
	</view>
</template>

<script>
	import Customer from './components/Customer.vue'
	import Produce from './components/Produce.vue'
	import Logistics from './components/Logistics.vue'
	export default {
		components: {
			Customer,
			Produce,
			Logistics
		},
		data() {
			return {
				// productionNum: 0
			}
		},
		onShow() {
			this.$nextTick(() => {})
			const roleType = uni.getStorageSync('roleType')
			if (!roleType) {
				uni.redirectTo({
					url: '/pages/login/role'
				})
				return
			}
			this.$store.commit('SET_ROLE_TYPE', roleType)
			if (this.roleType === 'staff') {
				this.funGetStaffInfo()
			} else {
				this.funGetUserInfo()
				this.$refs.customerRef.funOnShow()
			}
		},
		methods: {
			async funGetUserInfo() {
				const result = await this.$api.postUserInfo({
					openid: uni.getStorageSync('openid')
				})
				this.$store.commit('SET_USER_INFO', result.data)
			},
			async funGetStaffInfo() {
				const result = await this.$api.getStaffInfo()
				const staffRole = result.roles[0]
				if (staffRole !== 'shengchan' && staffRole !== 'wuliu') {
					uni.showToast({
						title: '没有权限，请联系平台',
						icon: 'none'
					})
					this.$store.dispatch('LogOut')
					uni.redirectTo({
						url: '/pages/login/role'
					})
					return
				}
				this.$store.commit('SET_STAFF_ROLE', staffRole)
				this.$store.commit('SET_STAFF_INFO', result.user)
			},
		},
	}
</script>

<style lang="scss" scoped></style>